home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 9
/
Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO
/
015a
/
uecho.zip
/
UECHO.C
next >
Wrap
C/C++ Source or Header
|
1993-04-12
|
8KB
|
265 lines
/*****
** Author : E. Heverly
** Date : 03/01/93
** Purpose : Provide Unix like echo utility for DOS.
** Contact : E. Heverly
** 28661 Palomino
** Warren, MI 48093 (313) 354-1370 - daytime
** (313) 558-9528 - Evenings
** (Sorry - no e-mail address)
**
** Features: This utility provides the functions of the UNIX echo
** (shell builtin) including:
** - No carriage returns \c
** - Octal notation printing \nnn
** - Alert (ring bell) \a
** - Backspace \b
** - Formfeed \f
** - Carriage Return (no newline) \r
** - Vertical Tab \v
** - Tab \t
** - Print current directory list *
**
** Note: This utility is also helpful since if the following:
** uecho set VAR=1 >> AUTOEXEC.BAT
** was placed in a .BAT file only the sed VAR=1 would be in
** in the AUTOEXEC.BAT, where the DOS echo command would put
** in the additional trailing spaces.
**
**
** Compile : I created this program using Microsoft (tm) Quick-C
** and compiled it with the same. No special header files
** are required outside of what MS provides with Quick-C.
**
** Testing : I have tested it in DOS 3.3 and 5.0. This testing
** includes all special functions listed above as well as a
** standard echo text.
**
** Example : C:\> uecho Hello \n\n\n Welcome \rWelcome\n \007
** Produces: Hello
**
**
** Welcome
** <Computers Beep>
** C:\>
**
** Notes : MS, Microsoft, and Quick-C are trademarks of Microsoft.
** UNIX is a registered trademark of AT&T.
**
*****/
#include <dos.h>
#include <stdlib.h>
#include <string.h>
void print_help(void);
void fileinfo( struct find_t *find );
int main(int argc, char *argv[])
{
struct find_t find;
char *wildspec[]={"*.*"};
char _far *CmdLine;
char cmdline[120];
char swch;
char chr;
int oct;
char CC;
char *s;
char *x;
int i,
rtn=0,
o,
acc,
end=0,
newline=0,
cstrlen,
tmp=0;
for (acc=0 ; acc < argc ; ++acc)
{
s=(argv[acc]);
if ( *s == '-' )
{
s=(++argv[acc]);
switch (*s)
{
case '?': /* if -? was on */
print_help(); /* the command line */
break; /* print help */
default:
break;
}
}
}
FP_SEG(CmdLine) = _psp; /* segment address */
FP_OFF(CmdLine) = 0x81; /* offset into segment*/
cstrlen=(_fstrlen ( CmdLine ));
for ( i=0; i <= cstrlen ; i++ ) /* get the command */
{ /* line far into */
CC=*CmdLine++; /* a usable string */
if ( CC == '\r' ) /* Convert upto the */
{ /* first carriage */
end=1; /* return in far */
cmdline[i]='\0'; /* & set end of */
} /* string */
else /* */
{ /* */
if ( end == 0 ) /* */
cmdline[i] = CC; /* */
} /* */
} /* */
cstrlen=( strlen ( cmdline )); /* Get input length */
CC='N';
o=cstrlen;
o--;
for ( i=o; i > 0 ; i-- )
{
if (cmdline[i] == 0x20 && CC == 'N' )
cstrlen=i;
else
CC='Y';
}
/* printf("cstrlen %u", cstrlen); */
for ( i=1 ; i < cstrlen ; i++)
{
if ( cmdline[i] == '\\' )
{
++i;
swch=cmdline[i];
switch (toupper(swch))
{
case 'N': /* print newline */
printf("\n");
break;
case 'R': /* print carriage return */
printf("\r");
break;
case 'T': /* print horz. tab */
printf("\t");
break;
case '\"': /* print double quote */
printf("\"");
break;
case '*': /* print asterisk */
printf("*");
break;
case 'A': /* ring bell */
printf("\a");
break;
case 'B': /* print backspace */
printf("\b");
break;
case 'F': /* print form feed */
printf("\f");
break;
case 'V': /* print vertical tab */
printf("\v");
break;
case '\\': /* print backslash */
printf("\\");
break;
case '\'': /* print single quote */
printf("\'");
break;
case 'C': /* DON'T Print a newline */
newline=1;
break;
case '0': /* Print char in octal not.*/
oct=0;
chr=(cmdline[i + 3]);
if ( chr == ' '|| chr == '\0' )
{ /* this side is for \nnn */
oct=(oct + ((cmdline[++i] - '0') * 8 ));
oct=(oct + (cmdline[++i] - '0'));
printf("%c", oct);
}
else
{ /* this side is for \nnnn */
oct=(oct + ((cmdline[++i] - '0') * 8 * 8));
oct=(oct + ((cmdline[++i] - '0') * 8 ));
oct=(oct + (cmdline[++i] - '0'));
printf("%c", oct);
}
i++;
break;
}
}
else
{
swch=cmdline[i];
switch (toupper(swch))
{
case '\"': /* DON'T print quotes */
break;
case '*': /* print directory */
printf("\n");
rtn=(_dos_findfirst(wildspec[0], 0xffff, &find ) );
if ( rtn == 0 )
{
while( !_dos_findnext( &find ) )
fileinfo( &find );
}
else
printf("DOS error code: %d", rtn);
find;
break;
default:
printf("%c", cmdline[i]); /* Print input characters*/
break;
}
}
}
if ( newline == 0 ) /* if /c was not entered */
printf("\n"); /* print a newline */
exit(0);
}
/* Print *.* in curent directory similar to * in UNIX echo utility */
void fileinfo( struct find_t *pfind )
{
if( pfind->attrib & _A_SUBDIR )
printf ("[%-12s] ", pfind->name );
else
printf( " %-12s ", pfind->name );
}
void print_help(void)
{
printf("Usage: uecho text <options> \n");
printf("Where: \\c - do not print a newline at the end\n");
printf(" \\a - alert (bell)\n");
printf(" \\b - backspace\n");
printf(" \\f - formfeed\n");
printf(" \\n - newline\n");
printf(" \\r - carriage return\n");
printf(" \\v - vertical tab - \v \n");
printf(" \\t - tab\n");
printf(" \\ - backslash\n");
printf(" \\\" - double quote\n");
printf(" \\' - single quote\n");
printf(" \\nnn - ascii notation of octal number\n");
printf("Examp: uecho Hello \\n Press Any Key \\c \n");
printf(" would produce Hello <return> Press Any KeyC:\\");
exit (0);
}